package com.lostandfound.action;

import com.lostandfound.entity.TestBean;
import com.lostandfound.service.TestServiceI;
import com.opensymphony.xwork2.ActionSupport;

import java.util.Date;
import java.util.HashMap;
import java.util.UUID;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;

/**  
* 
*  
* @author xuao  
* @date 2018��3��8��
*/
@ParentPackage("basePackage")
//@Action(value="strust2Test")//使用convention-plugin插件提供的@Action注解将一个普通java类标注为一个可以处理用户请求的Action，Action的名字为struts2Test
//@Results( { @Result(name = ActionSupport.SUCCESS, type = "json"),
//@Result(name = ActionSupport.ERROR, type = "json") })
@Namespace("/")//使用convention-plugin插件提供的@Namespace注解为这个Action指定一个命名空间
public class TestAction {
    
    /**
     * 注入userService
     */
    @Autowired
    private TestServiceI testService;
    
    private HashMap<String, String> map;
    private String result;

    public String getResult() {
		return result;
	}
	public void setResult(String result) {
		this.result = result;
	}
	
	public HashMap<String, String> getMap() {
		return map;
	}
	public void setMap(HashMap<String, String> map) {
		this.map = map;
	}
	
	@Action(value="getUserByName", results={@Result(type="json", params={"root","map"})})
	public String getJson(){
		System.out.println("**返回json--");
		System.out.println(map.get("name"));
		return ActionSupport.SUCCESS;
	}

	/**
     * http://localhost:8080/SSHE/strust2Test!test.action
     * MethodName: test
     * Description: 
     * @author xudp
     */
    public void test(){
        System.out.println("进入TestAction");
        testService.test();
    }
    
    /**
     * http://localhost:8080/SSHE/strust2Test!saveUser.action
     */
    public void saveUser(){
        TestBean testBean = new TestBean();
        testBean.setId(UUID.randomUUID().toString().replaceAll("-", ""));
        testBean.setName("xdp孤傲苍狼");
        testBean.setPwd("123456");
        testBean.setCreatedatetime(new Date()); 
        testService.save(testBean);
    }
}